import {$axios} from '@/utils/axios.js';
import config from "@/config";

// 5.区域集合预报模块

// 5.1 页面加载
export function pageLoadInfo() {
    return $axios.post('/grapes_reps/accu_prcp/page_load_info').then(res => {
        const oldData = res.data;
        const newData = [];
        for (let i = 0; i < oldData.mode.length; ++i) {
            newData.push({
                mode: oldData.mode[i],
                dateList: oldData['dates_list'][i],
                // 默认选中'grapes_reps'
                isSelected: 'grapes_reps'.equals(oldData.mode[i]),
            });
        }
        res.data = newData;
        return Promise.resolve(res);
    });
}

// 5.2 评分数据请求
export function skillScores(data) {
    return $axios.post('/grapes_reps/accu_prcp/skill_scores', data).then(res => {
        const oldData = res.data;
        res.data = {
            xs: oldData['data_x'],
            ys: oldData['data_y'],
        };
        const {ys} = res.data;
        for (let i = 0; i < ys.length; ++i) {
            ys[i] = ys[i].map(y => y === config.NAN_NUMBER ? null : y);
        }
        return Promise.resolve(res);
    });
}